// minibossnpc.txt
// Like basicnpc, but character automatically talks to party when they get 
// within 6 spaces or combat starts. The dialogue is meant to only
// be said once, and not again. This script is meant to be for
// foes of the party.
// Memory Cells:
//   Cell 0 - How creature moves.
//     0 - If 0, wander randomly. 
//     1 - Stands still until a target appears.
//     2 - Completely immobile, even if target appears.

//   Cell 3 - Dialogue node the character talks from.

// percent adjusts
// 0 - physical evasion %, 1 - magical evasion %, 2 - stun resist %, 3 - curse resistance %,
// 4 - bleeding resistance %, 5 - poison resistance %, 6 - speed bonus %, 7 - healing bonus %,
// 8 - buff duration %, 9 - debuff duration %, 10 - hit chance %
// 11 - critical hit bonus %, 12 - mental resist %

// base adjusts
// 0 - physical damage, 1 - magical damage, 2 - physical armor, 3 - magical armor

begincreaturescript;

variables;

short i,target;
short tried_return = 0;
short talk_done = 0;
short last_abil;
short mess1 = 0;
short x1 = 0;
short y1 = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Arthchimedes");
	if (get_level(ME) < 18)
		set_level(ME,18);
	change_max_health(ME,250);
	set_boss_level(ME,2);
	
	sf(58,15,1);
	
	
	//set_new_abil(ME,);
	add_ability(ME, 7, 284, 0);

	//place_particle_num(ME,short which_particle,12,8);
	//place_particle_num(ME,short which_particle,13,8);

	set_percent_adjust(ME,6,-50);
	set_percent_adjust(ME,10,30);

	set_amount_adjust(ME,0,2);
	set_amount_adjust(ME,1,10);
	
	set_walk_speed(ME,0);
	last_abil = get_current_tick();
	
	if (gf(58,12) > 0) {
		erase_char(ME);
		}
	break;

beginstate DEAD_STATE;
	sf(58,12,1);
	sf(58,24,1);
	clear_town(ME);
	award_party_xp(SMALL_QUEST_XP);
	erase_char(5869);
	begin_talk_mode(14);
break;

beginstate START_STATE; 

		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	// Look for a target, attack it if visible
	if (get_foe_target(ME,8,0)) {

		if (dist_to_party() > 8)
			approach_char(ME,30000,7);
			else {
				do_attack();
				set_state(3);
				}
		}
		
	// Have I been hit? Strike back!
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());

		do_attack();
		set_state(3);
		}


	// if we're in combat and the above didn't give me anything to do, just
	// stop now. Otherwise, game will keep running script, and that eats up CPU time.
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking

	if (target_ok() == FALSE)
		set_state(START_STATE);
		
	if ((my_dist_from_start() >= 25) && (tried_return == 0)) {
		tried_return = 1;
		set_foe_target(ME,-1);
		return_to_start(ME,2);
		set_state(4);
		}

	do_attack();
break;

beginstate EVERY_TURN_STATE;
	if (get_attitude(ME) < 10)
		end();
		
	
	if ((tick_difference(last_abil,get_current_tick()) > 0) && (is_combat())) {
		last_abil = get_current_tick();
		run_char_animation(3,1,35);	
		pc_heard_sound_delay(718,100);	

		inc_flag(58,15,1);
		
		x1 = 0; y1 = 0;
		
		if (gf(58,15) > 12)
			sf(58,15,0);
		if (gf(58,15) == 1) {
			set_terrain_string("The room grows very cold.");
			}
		if (gf(58,15) == 2) {
			set_terrain_string("The room grows much colder.");
			}
		if (gf(58,15) == 3) {
			set_terrain_string("The room is filled with a freezing wind. It blows the torch out, but another one flares to life.");
			x1 = 45; y1 = 29;
			}
		if (gf(58,15) == 4) {
			set_terrain_string("The room grows very cold.");
			}
		if (gf(58,15) == 5) {
			set_terrain_string("The room grows much colder.");
			}
		if (gf(58,15) == 6) {
			set_terrain_string("The room is filled with a freezing wind. It blows the torch out, but another one flares to life.");
			x1 = 36; y1 = 34;
			}
		if (gf(58,15) == 7) {
			set_terrain_string("The room grows very cold.");
			}
		if (gf(58,15) == 8) {
			set_terrain_string("The room grows much colder.");
			}
		if (gf(58,15) == 9) {
			set_terrain_string("The room is filled with a freezing wind. It blows the torch out, but another one flares to life.");
			x1 = 45; y1 = 34;
			}
		if (gf(58,15) == 10) {
			set_terrain_string("The room grows very cold.");
			}
		if (gf(58,15) == 11) {
			set_terrain_string("The room grows much colder.");
			}
		if (gf(58,15) == 12) {
			set_terrain_string("The room is filled with a freezing wind. It blows the torch out, but another one flares to life.");
			x1 = 36; y1 = 29;
			}
		if (x1 > 0) {
			play_sound(712);
			run_text_on_char(ME,"Sends icy wind!",0);
			
			i = get_pc_id(0);
			if ((i >= 0) && (char_ok(i)) && (dist_to_loc(i,x1,y1) > 3)) {
				run_text_on_char(i,"Freeze!",0);
				damage_char(i,get_max_health(i) / 2,1);
				if (difficulty() > 1)
					set_char_status(i,5,10);
				}
			i = get_pc_id(1);
			if ((i >= 0) && (char_ok(i)) && (dist_to_loc(i,x1,y1) > 3)) {
				run_text_on_char(i,"Freeze!",0);
				damage_char(i,get_max_health(i) / 2,1);
				if (difficulty() > 1)
					set_char_status(i,5,10);
				}
			i = get_pc_id(2);
			if ((i >= 0) && (char_ok(i)) && (dist_to_loc(i,x1,y1) > 3)) {
				run_text_on_char(i,"Freeze!",0);
				damage_char(i,get_max_health(i) / 2,1);
				if (difficulty() > 1)
					set_char_status(i,5,10);
				}
			i = get_pc_id(3);
			if ((i >= 0) && (char_ok(i)) && (dist_to_loc(i,x1,y1) > 3)) {
				run_text_on_char(i,"Freeze!",0);
				damage_char(i,get_max_health(i) / 2,1);
				if (difficulty() > 1)
					set_char_status(i,5,10);
				}
			i = get_pc_id(4);
			if ((i >= 0) && (char_ok(i)) && (dist_to_loc(i,x1,y1) > 3)) {
				run_text_on_char(i,"Freeze!",0);
				damage_char(i,get_max_health(i) / 2,1);
				if (difficulty() > 1)
					set_char_status(i,5,10);
				}
			i = get_pc_id(5);
			if ((i >= 0) && (char_ok(i)) && (dist_to_loc(i,x1,y1) > 3)) {
				run_text_on_char(i,"Freeze!",0);
				damage_char(i,get_max_health(i) / 2,1);
				if (difficulty() > 1)
					set_char_status(i,5,10);
				}
			i = get_pc_id(6);
			if ((i >= 0) && (char_ok(i)) && (dist_to_loc(i,x1,y1) > 3)) {
				run_text_on_char(i,"Freeze!",0);
				damage_char(i,get_max_health(i) / 2,1);
				if (difficulty() > 1)
					set_char_status(i,5,10);
				}
			i = get_pc_id(7);
			if ((i >= 0) && (char_ok(i)) && (dist_to_loc(i,x1,y1) > 3)) {
				run_text_on_char(i,"Freeze!",0);
				damage_char(i,get_max_health(i) / 2,1);
				if (difficulty() > 1)
					set_char_status(i,5,10);
				}

			set_terrain(1,36,29,604);
			set_terrain(1,36,34,604);
			set_terrain(1,45,29,604);
			set_terrain(1,45,34,604);
			
			if (gf(58,15) == 3)
				set_terrain(1,36,34,607);
			if (gf(58,15) == 6)
				set_terrain(1,45,34,607);
			if (gf(58,15) == 9)
				set_terrain(1,36,29,607);
			if (gf(58,15) == 12)
				set_terrain(1,45,29,607);
		if (mess1 == 0) {
			mess1 = 1;
			begin_talk_mode(15);
			}
			}
			else run_text_on_char(ME,"Calls cold.",0);

		
		}
		
		
//	run_char_animation(3,1,35);	
	//	pc_heard_sound_delay(700,100);	
	//	end();
	//	}

	//	run_char_animation(3,1,35);	
	//	pc_heard_sound_delay(700,100);	

	//	summon_creature(which_char);
	//	set_summon_level(which_char,1);	
	//	place_particle_num(ME,1077,9,8);
	//	run_text_on_char(which_char,"Bamf!",0);

	//run_text_on_char(short which_char_or_group,char *text,short color)
	//add_ability(, 15, which_ability, 0);
	
	//if ((mess1 == 0) && (get_health(ME) < (get_max_health(ME) * 5) / 10)) {
	//	mess1 = 1;
	//	}
break;

beginstate 4; // returning to start
	if (my_dist_from_start() < 10)
		set_state(START_STATE);

	// Have I been hit? Strike back!
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	
	return_to_start(ME,2);
break;

beginstate TALKING_STATE;

	talk_done = 1;
	talk_no_exit(40);
break;